import os
import time
import sys

# port = "/dev/cu.SLAB_USBtoUART"
port = "COM4"

def upload(file):
    cmd = "ampy -p %s put %s" % (port, file)
    print("Uploading file: %s" % file)
    os.system(cmd)
    print("Done")
    # time.sleep(1)

def main():
    for dir, folders, files in os.walk("./src"):
        tmp = folders + files
        # print("%s: %s %s"%(dir, folders, files))
        for filename in tmp:
            upload("%s/%s" % (dir, filename))


try:
    if len(sys.argv) == 1:
        main()
    elif len(sys.argv) == 2:
        file = sys.argv[1]
        upload(file)
except KeyboardInterrupt:
    print("Terminated")